package cn.rubintry.bug.hunting.common.http.viewmodel

import androidx.activity.ComponentActivity
import androidx.lifecycle.MutableLiveData
import cn.rubintry.bug.hunting.common.http.api.WebApi
import cn.rubintry.bug.hunting.common.manager.UserManager
import cn.rubintry.bug.hunting.pojo.ArticleDetailModel
import cn.rubintry.bug.hunting.pojo.BaseModel
import cn.rubintry.bug.lib.network.http.NetApiManager
import cn.rubintry.bug.lib.network.http.viewmodel.BaseViewModel

class ArticleViewModel() : BaseViewModel() {

    val articleData = MutableLiveData<BaseModel<ArticleDetailModel>>()


    fun getArticleById(id: String){
        request<WebApi, BaseModel<ArticleDetailModel>>(
            NetApiManager.getInstance().getApi(WebApi::class.java),
            WebApi::getArticleById,
            { data ->
                data?.let {
                    articleData.value = it
                }
            },id)
    }


    fun addToHistory(id: String , title  :String, sampleContent: String){
        request(
            NetApiManager.getInstance().getApi(WebApi::class.java),
            WebApi::addToHistory,{}, UserManager?.getInstance()?.getUserData()?.detail?.id ?: "",
            id,
            title,
            sampleContent,
            UserManager.getInstance().getUserData()?.token ?: ""
        )
    }
}